Cn_Indexbus ={
	editor : null//全局变量
	//初始化
	,init : function(){
		uid = Jes.request('uid');
		if(uid==null||uid==''){
			Jes.alert('该商家用户不存在');
			history.go(-1);
			return;
		}else{
			Jes.setToday('date');
			Cn_Indexbus.queryBusinfo(uid);//商家信息
			Comm.rightRecommUser(null,null,null);//右侧好友推荐
			Comm.rightRecommAct(null,'recommAct');//右侧活动推荐
			Cn_Index.queryTopic('all_topic',null,1);
			Cn_Indexbus.discuss();//用户评论
		}
	}
	//查询商家信息
	,queryBusinfo : function(uid){
		/*
		if(userInfo.userid==uid){//当前用户就是商家  显示增加修改
			showhid('modifyinfo');
			showhid('editcontent');
		}
		*/
		Jes.query('businfo_query_sql@bus',{paraObj:"{userid:'"+ uid +"'}",isSess:0,isLoad:false},function(data){
			if(data.length==0){
				alert('该商家信息还没完善,等会再来访问吧');
				history.go(-1);
				return;
			}
			var data = data[0];
			Jes.setFormValue("form1",data);
			//Jes.hide('yhtable');
			Jes.html('img_sj','<img width="180" height="180" src= "'+CONFIG_DATA.headpath+data.pic+'"/>');
			Jes.html('address','地址：<span class="con">' + data.address + '</span>');
			Jes.html('address1','线下店地址(<span >' + data.address + '</span>)');
			Jes.html('telephone','电话：<span class="con">' + data.tel + '</span>');
		//	Jes.html('zhekuo','今日折扣:  <span class="bigred2">' + Cn_Indexbus.getWeekyh(data)+'</span>折');
			if(data.money!=null){
				Jes.html('renju','参考人均：<span class="con">' + data.money + '</span>');
			}
			Jes.html('sjeditcon',data.intro);//详细介绍内容
			Jes('content').value = data.intro;//隐藏内容
			Jes('busid').value= data.busid;
			Jes.locate(data.address,'sj_map');//地图定位
		});
	}
	//编辑文本内容
	,showContent : function(obj){
		Cn_Indexbus.initCKEditor();
		Jes.hide('sjeditcon');
		Jes.hide('editcontent');
		Jes.show('divcontent');
	}
	//初始化ckedit
	,initCKEditor : function(){
		var opts = {
            filebrowserImageBrowseUrl: '/browser/browse.php?type=Images',
            filebrowserImageUploadUrl: '/uploader/upload.php?type=Images'
        };
       editor = CKEDITOR.replace("content",opts);
	}
	//保存content
	,save : function(){
		var content = CKEDITOR.instances.content.getData();
		Jes.executeSql({ids:userInfo.userid,content:content,sql:'savecontent_update_hql'},function(){
			Jes.hide('divcontent');
			Jes.show('sjeditcon');
			Jes.show('editcontent');
			if(editor){
				editor.destroy();
				editor = null;
			}
			alert('保存成功');
		});
	}
	//优惠初始化
	,yhlog : function(){
		var page = page || 1,pageSize = pageSize|| 15;
		Jes.page('yhlog_query_sql@bus',{paraObj:"{busid:'"+ uid +"'}"},function(data){
			var html = '';data = data.pageList;
			for(var i=0;i<data.length;i++){
				html = '<tr><td>'+data[i].acttime+' '+data[i].acthour+'</td><td class="tabcon">'+ data[i].discount +'</td><td>代金券</td></tr>';
			}
			$('#yhlog').html(html);
		});
	}
	//活动记录 初始化
	,actlog : function(){
		var page = page || 1,pageSize = pageSize|| 15;
		Jes.query('actlog_query_sql@bus',{paraObj:"{userid:'"+ uid +"'}",page:page,pageSize:pageSize},function(data){
			var html = '';
			for (var i = 0; i < data.length; i++) {
            	html = html + '<tr><td><a href="./person.html?id='+data[i].userid+'" class="name"  title="点击查看详情">'+data[i].loginid+'</a></td><td>'+data[i].money*data[i].factnum +'</td><td>'+data[i].factnum+'</td><td>'+data[i].acttime+'</td></tr>';
            }
            $('#actlog').html(html);
		});
	}
	//用户评论 初始化
	,discuss : function(){
		if(!Jes.userSess())return;
		var uid = Jes.request('uid');
		var isMy = false;
		if(uid==userInfo.userid){isMy=true};
		Jes.query('userimpress_query_sql@idx',{paraObj:"{userid:'"+ uid +"'}",isLoad:false},function(data){
			var html ='';
			for(var i=0;i<data.length;i++){
				html += '<tr><td><a href="../act/person.html?id='+ data[i].pluserid +'" class="name">'+data[i].loginid+'</a> </td>'
						+'<td class="tabcon">	<p>	'+data[i].content+'	</p></td>'
						+'<td>	'+data[i].createtime.substr(0,16)+'	</td>'
						+'</tr>';
			}
			$('#plcontent').html(html);
		});
	}
	//tab页点击
	,tabChange : function(num){
		for(var i=1;i<4;i++){
			//	$('#tab1').className="tabseled3";
			if(i==num){
				$('#tab'+num).className="tabseled3";//ddClass('tabseled3');
				Jes.show('tdivs'+num);
			}else{
				$('#tab'+i).className="tabnoseled3";
				//$('#tab'+i).removeClass('tabseled3').addClass('tabnoseled3');
				Jes.hide('tdivs'+i);
			}
		}
	}
	//判断今天 取优惠字段
	,getWeekyh : function(data){
		var d=new Date();
		var i = d.getDay();
		switch(i){
			case 0 :  if(data.sun==null) { return '无折扣'}else{return data.sun};
			case 1 : if(data.mon==null) { return '无折扣'}else{return data.mon}; 
			case 2 : if(data.tue==null) { return '无折扣'}else{return data.tue};
			case 3 : if(data.wed==null) { return '无折扣'}else{return data.wed};
			case 4 : if(data.thu==null) { return '无折扣'}else{return data.thu};
			case 5 : if(data.fri==null) { return '无折扣'}else{return data.fri};
			case 6 : if(data.sat==null) { return '无折扣'}else{return data.sat};
		}
	}
	
}
